﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HRM.DAL.DAO;
using HRM.Models;

namespace HRM.Controllers
{ 
    public class IncrementController : Controller
    {
        private HRMDBContext db = new HRMDBContext();

        //
        // GET: /Increment/

        public ViewResult Index()
        {
            var increments = db.Increments.Include(i => i.Employee);
            return View(increments.ToList());
        }

        //
        // GET: /Increment/Details/5

        public ViewResult Details(int id)
        {
            Increment increment = db.Increments.Find(id);
            return View(increment);
        }

        //
        // GET: /Increment/Create

        public ActionResult Create()
        {
            ViewBag.EmployeeId = new SelectList(db.Employees, "EmployeeId", "Name");
            return View();
        } 

        //
        // POST: /Increment/Create

        [HttpPost]
        public ActionResult Create(Increment increment)
        {
            if (ModelState.IsValid)
            {
                db.Increments.Add(increment);
                db.SaveChanges();
                return RedirectToAction("Index");  
            }

            ViewBag.EmployeeId = new SelectList(db.Employees, "EmployeeId", "Name", increment.EmployeeId);
            return View(increment);
        }
        
        //
        // GET: /Increment/Edit/5
 
        public ActionResult Edit(int id)
        {
            Increment increment = db.Increments.Find(id);
            ViewBag.EmployeeId = new SelectList(db.Employees, "EmployeeId", "Name", increment.EmployeeId);
            return View(increment);
        }

        //
        // POST: /Increment/Edit/5

        [HttpPost]
        public ActionResult Edit(Increment increment)
        {
            if (ModelState.IsValid)
            {
                db.Entry(increment).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.EmployeeId = new SelectList(db.Employees, "EmployeeId", "Name", increment.EmployeeId);
            return View(increment);
        }

        //
        // GET: /Increment/Delete/5
 
        public ActionResult Delete(int id)
        {
            Increment increment = db.Increments.Find(id);
            return View(increment);
        }

        //
        // POST: /Increment/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            Increment increment = db.Increments.Find(id);
            db.Increments.Remove(increment);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}